package com.ruicar.afs.cloud.afscase.contract.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.afscase.contract.service.AggregationService;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseBaseInfo;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseContractInfo;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseCustInfo;
import com.ruicar.afs.cloud.afscase.infomanagement.service.CaseBaseInfoService;
import com.ruicar.afs.cloud.afscase.infomanagement.service.CaseContractInfoService;
import com.ruicar.afs.cloud.afscase.infomanagement.service.CaseCustInfoService;
import com.ruicar.afs.cloud.afscase.loanactivatepool.entity.LoanActivatePool;
import com.ruicar.afs.cloud.afscase.loanactivatepool.service.LoanActivateService;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.common.modules.afscorebusiness.enums.*;
import com.ruicar.afs.cloud.common.modules.contract.cms.vo.CmsProgressInquiryDataVo;
import com.ruicar.afs.cloud.common.modules.contract.cms.vo.LoanProgressVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class AggregationServiceImpl implements AggregationService {
    private CaseCustInfoService caseCustInfoService;
    private CaseBaseInfoService caseBaseInfoService;
    private CaseContractInfoService caseContractInfoService;
    private LoanActivateService loanActivateService;

    public CmsProgressInquiryDataVo getLoanProgressByIdCard(String idCard){
        CmsProgressInquiryDataVo cmsProgressInquiryDataVo=new CmsProgressInquiryDataVo();
        cmsProgressInquiryDataVo.setIdCard(idCard);
        List<CaseCustInfo> custList=caseCustInfoService.list(Wrappers.<CaseCustInfo>lambdaQuery().eq(CaseCustInfo::getCertNo,idCard)
                .eq(CaseCustInfo::getCustRole, CustRoleEnum.MIANCUST.getCode()));
        List<LoanProgressVo> apphislist= new ArrayList<>();
        custList.forEach(caseCustInfo -> {
            CaseBaseInfo caseBaseInfo=caseBaseInfoService.getOne(Wrappers.<CaseBaseInfo>lambdaQuery().eq(CaseBaseInfo::getApplyNo,caseCustInfo.getApplyNo()));
            List<CaseContractInfo> caseContractInfoList=caseContractInfoService.list(Wrappers.<CaseContractInfo>lambdaQuery().eq(CaseContractInfo::getApplyNo,caseBaseInfo.getApplyNo()));
            if(ObjectUtils.isEmpty(caseContractInfoList)){
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.SUBMITTED))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.WAIT_QUERY))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CALL_BACK_WAIT_SUBMIT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.DRAFT))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("5");//已提交
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ALLOCATION))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.TASK_ASSIGN))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.TASK_ASSIGNING))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.WAIT_CHECK))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_APPROVED))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_REJECT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_CONDITIONAL))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.VISIT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.PAUSE))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVOCATION))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVISE_PARSE))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVISE_REPLY))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("6");//审核中
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.APPROVED))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3"); //审批阶段
                    loanProgressVo.setPayStatus("7");//核准
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CONDITIONAL_APPROVE))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("8");//建议核准
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REJECT))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("9");//拒绝
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REPEAL))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.INVALID))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CANCEL_ADVICE_CONDITIONAL))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(idCard);
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("10");//拒绝
                    apphislist.add(loanProgressVo);
                }
            }else{
                caseContractInfoList.forEach(caseContractInfo -> {
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_SUBMIT.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_PRE_PROCESS.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_QUEUE.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.ASSIGNING.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.WAIT_ASSIGN.getState())){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(idCard);
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//审批阶段
                        loanProgressVo.setPayStatus("11");//放款已提交
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_APPROVE.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.SUSPEND_WAIT.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_CONFIRM.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_REVIEW_RETURN.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_REPAIR.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_RETURN.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_PRE_APPROVE.getState())){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(idCard);
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("12");//放款审核中
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_APPROVE_DONE.getState())&&ContractStatusEnum.contractEffective != caseContractInfo.getContractStatus()){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(idCard);
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("13");//放款审核中
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_DISCARD.getState())
                            ||caseContractInfo.getContractStatus().equals(ContractStatusEnum.contractCancel)
                            ||caseContractInfo.getContractStatus().equals(ContractStatusEnum.flatCancel)){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(idCard);
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("14");//放款取消
                        apphislist.add(loanProgressVo);
                    }
                    LoanActivatePool pool=loanActivateService.getOne(Wrappers.<LoanActivatePool>lambdaQuery().eq(LoanActivatePool::getContractNo,caseContractInfo.getContractNo()));
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_APPROVE_DONE.getState())
                            &&(!caseContractInfo.getGpsStatus().equals(AfsEnumUtil.key(GpsStatusEnum.PASS_AUDIT)))){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(idCard);
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("15");//放款取消
                        apphislist.add(loanProgressVo);
                    }
                });
            }
        });
        cmsProgressInquiryDataVo.setApphis(apphislist);
        return cmsProgressInquiryDataVo;
    }

    public CmsProgressInquiryDataVo getLoanProgressByApplyNo(String applyNo){
        CmsProgressInquiryDataVo cmsProgressInquiryDataVo=new CmsProgressInquiryDataVo();
        CaseCustInfo caseCustInfo=caseCustInfoService.getOne(Wrappers.<CaseCustInfo>lambdaQuery().eq(CaseCustInfo::getApplyNo,applyNo)
                .eq(CaseCustInfo::getCustRole, CustRoleEnum.MIANCUST.getCode()));
            CaseBaseInfo caseBaseInfo=caseBaseInfoService.getOne(Wrappers.<CaseBaseInfo>lambdaQuery().eq(CaseBaseInfo::getApplyNo,applyNo));
            if(ObjectUtils.isEmpty(caseBaseInfo)){
                return new CmsProgressInquiryDataVo();
            }
            List<CaseContractInfo> caseContractInfoList=caseContractInfoService.list(Wrappers.<CaseContractInfo>lambdaQuery().eq(CaseContractInfo::getApplyNo,caseBaseInfo.getApplyNo()));
        List<LoanProgressVo> apphislist= new ArrayList<>();
            if(ObjectUtils.isEmpty(caseContractInfoList)){
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.SUBMITTED))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.WAIT_QUERY))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CALL_BACK_WAIT_SUBMIT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.DRAFT))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("5");//已提交
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ALLOCATION))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.TASK_ASSIGN))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.TASK_ASSIGNING))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.WAIT_CHECK))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_APPROVED))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_REJECT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.ADVICE_CONDITIONAL))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.VISIT))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.PAUSE))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVOCATION))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVISE_PARSE))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REVISE_REPLY))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("6");//审核中
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.APPROVED))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3"); //审批阶段
                    loanProgressVo.setPayStatus("7");//核准
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CONDITIONAL_APPROVE))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("8");//建议核准
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REJECT))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("9");//拒绝
                    apphislist.add(loanProgressVo);
                }
                if(caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.REPEAL))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.INVALID))
                        ||caseBaseInfo.getBusinessStateIn().equals(AfsEnumUtil.key(BusinessStateInEnum.CANCEL_ADVICE_CONDITIONAL))){
                    LoanProgressVo loanProgressVo=new LoanProgressVo();
                    loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                    loanProgressVo.setCaseStatus("3");
                    loanProgressVo.setContractNo(caseCustInfo.getApplyNo());
                    loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                    loanProgressVo.setStageStatus("3");//审批阶段
                    loanProgressVo.setPayStatus("10");//拒绝
                    apphislist.add(loanProgressVo);
                }
            }else{
                caseContractInfoList.forEach(caseContractInfo -> {
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_SUBMIT.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_PRE_PROCESS.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_QUEUE.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.ASSIGNING.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.WAIT_ASSIGN.getState())){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//审批阶段
                        loanProgressVo.setPayStatus("11");//放款已提交
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_APPROVE.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.SUSPEND_WAIT.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_WAIT_CONFIRM.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_REVIEW_RETURN.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_REPAIR.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_RETURN.getState())
                            ||caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_PRE_APPROVE.getState())){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("12");//放款审核中
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_APPROVE_DONE.getState())){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("13");//放款审核中
                        apphislist.add(loanProgressVo);
                    }
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_DISCARD.getState())
                            ||caseContractInfo.getContractStatus().equals(ContractStatusEnum.contractCancel)
                            ||caseContractInfo.getContractStatus().equals(ContractStatusEnum.flatCancel)){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("14");//放款取消
                        apphislist.add(loanProgressVo);
                    }
                    LoanActivatePool pool=loanActivateService.getOne(Wrappers.<LoanActivatePool>lambdaQuery().eq(LoanActivatePool::getContractNo,caseContractInfo.getContractNo()));
                    if(caseContractInfo.getApplyStatus().equals(ApplyStatusEnum.LOAN_APPROVE_DONE.getState())
                            &&(!caseContractInfo.getGpsStatus().equals(AfsEnumUtil.key(GpsStatusEnum.PASS_AUDIT)))){
                        LoanProgressVo loanProgressVo=new LoanProgressVo();
                        loanProgressVo.setCertNo(caseCustInfo.getCertNo());
                        loanProgressVo.setCaseStatus("3");
                        loanProgressVo.setContractNo(caseContractInfo.getContractNo());
                        loanProgressVo.setCreateDate(caseCustInfo.getCreateTime());
                        loanProgressVo.setStageStatus("2");//放款阶段
                        loanProgressVo.setPayStatus("15");//放款取消
                        apphislist.add(loanProgressVo);
                    }
                });

            }
        cmsProgressInquiryDataVo.setIdCard(caseCustInfo.getCertNo());
        cmsProgressInquiryDataVo.setApphis(apphislist);
        return cmsProgressInquiryDataVo;
    }
}
